package com.longge;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class FindClosestElements {

    public List<Integer> findClosestElements(int[] arr, int k, int x) {

       return IntStream.of(arr).boxed().sorted(Comparator.comparingInt(a -> Math.abs(a - x))).limit(k).sorted().collect(Collectors.toList());

    }
}
